Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SLCORE-1032 Wrong token error during sync - [New design] #1187

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kirill-knize-sonarsource
Copy link
Contributor

@kirill-knize-sonarsource kirill-knize-sonarsource commented Dec 10, 2024

@kirill-knize-sonarsource kirill-knize-sonarsource marked this pull request as draft December 10, 2024 10:04
@kirill-knize-sonarsource kirill-knize-sonarsource force-pushed the feature/kk/wrong-token-during-sync-new-design branch 5 times, most recently from 0483733 to 84a4ae9 Compare December 19, 2024 08:46
@kirill-knize-sonarsource kirill-knize-sonarsource marked this pull request as ready for review January 6, 2025 08:58
@kirill-knize-sonarsource kirill-knize-sonarsource force-pushed the feature/kk/wrong-token-during-sync-new-design branch 7 times, most recently from 75de64c to 5361898 Compare January 8, 2025 14:20
@kirill-knize-sonarsource kirill-knize-sonarsource force-pushed the feature/kk/wrong-token-during-sync-new-design branch from 86acfa4 to bffb584 Compare January 9, 2025 10:38
Copy link
Contributor

@damien-urruty-sonarsource damien-urruty-sonarsource left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left some ideas for improvement, but it looks mostly good to me. You could remove [New design] from the PR title and the commit message. And the last thing, I am not sure we should merge this now, we should maybe make sure the notification is implemented on the IDE side?

@@ -47,19 +53,21 @@

@Named
@Singleton
public class ServerApiProvider {
public class ServerApiProvider implements ConnectionManager {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a strong reason to keep this interface and have a single implementation. Why about keeping only a ConnectionManager class?

private final URI sonarCloudUri;

public ServerApiProvider(ConnectionConfigurationRepository connectionRepository, ConnectionAwareHttpClientProvider awareHttpClientProvider, HttpClientProvider httpClientProvider,
SonarCloudActiveEnvironment sonarCloudActiveEnvironment) {
SonarCloudActiveEnvironment sonarCloudActiveEnvironment, SonarLintRpcClient client) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation issue?

}
cacheConnectionIdPerVersion.put(connectionId, version);
}
serverApiProvider.tryGetConnectionWithoutCredentials(connectionId)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked a bit more around this use case. In fact, the api/system/status call is not authenticated. So instead of having a method at the serverApiProvider level, I would find it more logical that the decision to not use authentication be made in SystemApi. But this has some impact in other places

* It's not a big problem because we don't use such requests during scheduled sync.
* They are mostly related to setting up the connection or other user-triggered actions.
*/
ServerApi getTransientConnection(String token, @Nullable String organization, String baseUrl);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this method should be located in ConnectionManager. As it's "transient" and by definition we won't keep state for it, and it's not (yet) a connection. I think it would simplify a bit the current ServerApiProvider which has a lot of entrypoints

return lastNotificationTime.plus(WRONG_TOKEN_NOTIFICATION_INTERVAL).isBefore(Instant.now());
}

private void notifyClientAboutWrongTokenIfNeeded() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it's the responsibility of the ServerConnection to notify to the client. I would find it more logical to have it in the ConnectionManager.

return Optional.empty();
}
return serverApi.get().hotspot().fetch(hotspotKey, cancelMonitor);
return serverApiProvider.withValidConnectionFlatMapOptionalAndReturn(connectionId,api -> api.hotspot().fetch(hotspotKey, cancelMonitor));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name of this method is a bit long. In fact this makes me wonder if Api classes should return Optionals at all, maybe they should instead let the errors bubble up?

@@ -137,4 +145,44 @@ private HttpClient getClientFor(EndpointParams params, Either<TokenDto, Username
userPass -> httpClientProvider.getHttpClientWithPreemptiveAuth(userPass.getUsername(), userPass.getPassword()));
}

@Override
public ServerConnection getConnectionOrThrow(String connectionId) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As shared earlier, I find the surface of methods quite large, so for people not familiar it might be complex to know which one to use. Do you think there is a way to simplify? Maybe we should at least document the different usages

Comment on lines +184 to +187
@VisibleForTesting
public Optional<ServerConnection> getValidConnection(String connectionId) {
return tryGetConnection(connectionId).filter(ServerConnection::isValid);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is used only in a single test, couldn't we get rid of it and use another method? I mean at least to not have it public and remove the annotation


@VisibleForTesting
public Optional<ServerConnection> getValidConnection(String connectionId) {
return tryGetConnection(connectionId).filter(ServerConnection::isValid);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A last thing, should we log that the connection is invalid? Maybe too noisy?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants